# import requests
# from lxml import etree
#
#
# url = 'https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2&cb=jQuery371023020196009126725_1762237116106&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23&fid=f3&pn=1&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=1762237116114'
# header = {
#     'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
#     'referer':'https://quote.eastmoney.com/center/gridlist.html'
# }
# res = requests.get(url, headers=header)
# print(res.text)




# 协程
# import asyncio
# import aiohttp
#
#
# header = {
#     'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
#     'referer':'https://quote.eastmoney.com/center/gridlist.html'
# }
#
# async def fetch(session, url):
#     async with session.get(url) as response:
#         items = response.json()
#         print(items)
#
# async def main():
#     urls = [f'https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2&fid=f3&pn={page}&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=1762237116114' for page in range(1, 274)]
#
#     async with aiohttp.ClientSession(headers=header) as session:
#         size = 5
#         for i in range(0, len(urls), size):
#             tasks = [fetch(session, url) for url in urls[i : i + size]]
#
#             await asyncio.gather(*tasks)
#             await asyncio.sleep(1)
#
#         # tasks = [fetch(session, url) for url in urls]
#         # await asyncio.gather(*tasks)
#
# asyncio.run(main())


# 多线程 线程池

from concurrent.futures import ThreadPoolExecutor
import os
import requests

header = {
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
    'referer':'https://quote.eastmoney.com/center/gridlist.html'
}
urls = [f'https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2&fid=f3&pn={page}&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=1762237116114' for page in range(1, 274)]

def fetch(url):
    res = requests.get(url, headers=header)
    print(res.json())
    # print(os.getpid())
with ThreadPoolExecutor(max_workers=5) as executor:
    for url in urls:
        executor.submit(fetch, url)

